package com.asus.open;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class MainActivity extends Activity {

    private Button btn_start;
    private int numberint = 1;
    private Spinner sp_number;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_start = findViewById(R.id.btn_start);
        sp_number = findViewById(R.id.sp_number);
        String[] mItems = getResources().getStringArray(R.array.Data);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, mItems);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp_number.setAdapter(adapter);

        sp_number.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                String[] Data = getResources().getStringArray(R.array.Data);

                numberint = Integer.parseInt(Data[i].replaceAll("包", "").trim());
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                sp_number.setSelection(0);
            }
        });
        sp_number.setSelection(0);
        btn_start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent mIntent = new Intent(getApplication(), OpenPackageActivity.class);
                mIntent.putExtra("NUMBER", numberint);
                startActivity(mIntent);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        sp_number.setSelection(0);
    }
}
